Bezier = Bezier or Class("Bezier")


function Bezier.point(p1, p2, p3, p4, t)
    return p1 * (1 - t) ^ 3 + 
    p2 * 3 * t * (1 - t) ^ 2 + 
    p3 * 3 * t ^ 2 * (1 - t) + 
    p4 * t ^ 3
end
function Bezier.points(p1, p2, p3, p4, segments)
    local points = {p1}
    for i = 1, segments do
        local t = i / segments
		local p = Bezier.point(p1, p2, p3, p4, t)
        table.insert(p)
    end
    return points
end